﻿using System;
using System.Collections.Generic;
using MugenInjection.Core;
using MugenInjection.Delegates;
using MugenInjection.Infrastructure;
using MugenInjection.Interface;

namespace MugenInjection.Scope
{
    /// <summary>
    ///     Represents the transient scope lifecycle.
    /// </summary>
    public sealed class TransientScopeLifecycle : DisposableObject, IScopeLifecycle
    {
        #region Fields

        private IScopeLifecycleContext _context;

        #endregion

        #region Implementation of IScopeLifecycle

        /// <summary>
        ///     Gets or sets the <see cref="IScopeLifecycleContext" />.
        /// </summary>
        public IScopeLifecycleContext Context
        {
            get
            {
                Validate.EnsureIsInitializedValue(_context, "Context");
                return _context;
            }
            set { _context = value; }
        }

        /// <summary>
        ///     Gets the actions that should be called before instances are deactivated via the binding.
        /// </summary>
        ICollection<Action<object, bool>> IScopeLifecycle.ReleaseObjectActions
        {
            get { return null; }
        }

        /// <summary>
        ///     Resolves instance for the specified <see cref="IBindingContext" /> from scope.
        /// </summary>
        /// <returns>An instance of the service.</returns>
        public object GetObjectFromScope()
        {
            return Context.ResolveCurrentService();
        }

        /// <summary>
        ///     Releases all objects in current scope.
        /// </summary>
        /// <param name="isNeedDisposeObject">Indicating that need trying dispose objects.</param>
        public void ReleaseObjects(bool isNeedDisposeObject)
        {
        }

        #endregion
    }
}